package com.d2.pay.rest;

import com.alibaba.fastjson.JSON;
import com.d2.pay.model.D2SendItem;
import com.d2.pay.netty.NettySession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * Auth: Alexander Lo
 * Date: 2020-03-24
 * Description:
 */
@RestController
@Slf4j
public class D2Controller {

    @Autowired
    private NettySession nettySession;



    @GetMapping("/send/sample")
    public String  send(){
        D2SendItem d2SendItem  = new D2SendItem();
        d2SendItem.setOrderIndex("110120");
        d2SendItem.setName("lalala");
        d2SendItem.setItemCode("cm1 ");
        d2SendItem.setQuality((byte)7);
        d2SendItem.setCount(500);

        System.err.println(Arrays.toString(d2SendItem.toBytes()));
        nettySession.sendMsg("1",d2SendItem.toBytes());
        return "发送成功---随机数字标记:" + Math.random();
    }

    @GetMapping("/send/str/{value}")
    public String send(@PathVariable("value") String value){
        System.err.println("sending");
        nettySession.sendMsg("1",value+"\n");
        return "发送成功---随机数字标记:" + Math.random();
    }


    @PostMapping("/d2send")
    public String send(D2SendItem d2SendItem){
        System.err.println(JSON.toJSONString(d2SendItem));
//        System.err.println("sending");
//        nettyClient.sendMsg(value+"\n");
        return "发送成功---随机数字标记:" + Math.random();
    }


}
